package com.atguigu.gulimall.member.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.member.entity.MemberLevelEntity;
import com.atguigu.gulimall.member.service.MemberLevelService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

/**
 * @className: MemberLevelController
 * @description: 会员等级控制器
 * @date: 2020/11/5
 * @author: cakin
 */
@RestController
@RequestMapping("member/memberlevel")
public class MemberLevelController {
    @Autowired
    private MemberLevelService memberLevelService;

    /**
     * 功能描述：会员等级列表
     *
     * @author cakin
     * @date 2020/11/5
     * @param params 过滤条件
     * @return R 返回给前端的数据
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberLevelService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 功能描述：会员等级详细信息
     *
     * @author cakin
     * @date 2020/11/5
     * @param id 会员等级id
     * @return R 返回给前端的数据
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberLevelEntity memberLevel = memberLevelService.getById(id);
        return R.ok().put("memberLevel", memberLevel);
    }

    /**
     * 功能描述：保存会员等级信息
     *
     * @author cakin
     * @date 2020/11/5
     * @param memberLevel 会员等级
     * @return R 返回给前端的数据
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberLevelEntity memberLevel){
		memberLevelService.save(memberLevel);
        return R.ok();
    }

    /**
     * 功能描述：修改会员等级信息
     *
     * @author cakin
     * @date 2020/11/5
     * @param memberLevel 会员等级
     * @return R 返回给前端的数据
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberLevelEntity memberLevel){
		memberLevelService.updateById(memberLevel);

        return R.ok();
    }

    /**
     * 功能描述：依据会员等级id列表批量删除会员等级信息
     *
     * @author cakin
     * @date 2020/11/5
     * @param ids 会员等级id列表
     * @return R 返回给前端的数据
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberLevelService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}
